package com.lanchetech.admin.service.impl;

import com.lanchetech.dao.AdminMapper;
import com.lanchetech.entity.Admin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

public class AdminCustomUserService implements UserDetailsService { //1
    @Autowired
    AdminMapper adminMapper;

    @Override
    public UserDetails loadUserByUsername(String username) { //2
        Admin admin = adminMapper.findOneByUsername(username);
        if (admin == null) {
            throw new UsernameNotFoundException("管理员不存在");
        }

        return admin;
    }

}
